<?php

class Users_EditInputView extends SrsUsersBaseView
{
	public function executeHtml(AgaviRequestDataHolder $rd)
	{
		$this->setupHtml($rd);

		$user = Doctrine_Query::create()
		        ->from('User')
			      ->where('id=?', $rd->getParameter('id'))
					  ->fetchOne();

		if (!$user instanceof User) return $this->forward404();

		$referer = $rd->getHeader('REFERER', $this->genUrl('user.read', array('id' => $user['id'])));

		$form = new AgaviParameterHolder(array(
			'user' => array(
				'email'  => $user['email'],
				'name'   => $user['name'],
				'role'   => $user['role'],
				'active' => $user['active'] ? 1 : 0,
				'phone'  => $user['phone'],
			),
			'referer' => $referer,
		));

		$this->populate('editUser', $form);

		$this->setAttribute('user', $user);
		$this->setAttribute('referer', $referer);
	}
}